import cv2

cat = cv2.imread('../images/cat.jpg')
cat_gray = cv2.cvtColor(cat, cv2.COLOR_BGR2GRAY)  # 灰度图

ret, cat_threshold = cv2.threshold(cat_gray, 127, 255, cv2.THRESH_BINARY)
# 小于127，设置为0，大于127，设置为255

ret, cat_threshold_inv = cv2.threshold(cat_gray, 127, 255, cv2.THRESH_BINARY_INV)
# 小于127，设置为255，大于127，设置为0

cv2.imshow('cat_gray', cat_gray)
cv2.imshow('cat_threshold', cat_threshold)
cv2.imshow('cat_threshold_inv', cat_threshold_inv)
cv2.waitKey(0)
cv2.destroyAllWindows()